import request from '@/utils/kafkaHttp'
const baseAll = '/kafkaRes/paas-kafka'
export default {
  kafkaPackFunction(uri, requestType, selectCluster, params) {
    const datas = {}
    datas.uri = uri
    datas.requestType = requestType
    datas.selectCluster = selectCluster
    if (params !== undefined) {
      datas.params = params
    }
    if (process.env.KAFKA_TYPE === 'paas') {
      return request({
        url: `${baseAll}/kafka/kafkaPack`,
        method: 'post',
        data: {
          arguments: datas
        },
        baseURL: '',
        noToken: ''
      })
    } else {
      if (requestType === 'post') {
        return request({
          url: `${baseAll}${uri}`,
          method: requestType,
          data: params,
          baseURL: '',
          noToken: ''
        })
      } else {
        return request({
          url: `${baseAll}${uri}`,
          method: requestType,
          params: params,
          baseURL: '',
          noToken: ''
        })
      }
    }
  },
  kafkaPackFunctionOri(uri, requestType, originalUri, selectCluster, params) {
    if (process.env.KAFKA_TYPE !== 'paas') {
      return this.kafkaPackFunction(uri, requestType, selectCluster, params)
    }
    const datas = {}
    datas.uri = uri
    datas.requestType = requestType
    datas.originalUri = originalUri
    datas.selectCluster = selectCluster
    if (params !== undefined) {
      datas.params = params
    }
    return request({
      url: `${baseAll}/kafka/kafkaPack`,
      method: 'POST',
      data: {
        arguments: datas
      },
      baseURL: '',
      noToken: ''
    })
  },
  getTopicSize(params) {
    return request({
      url: `${baseAll}/kafka/getTopicSize`,
      method: 'POST',
      data: params,
      baseURL: '',
      noToken: ''
    })
  },
  saveTopics(params) {
    return request({
      url: `${baseAll}/kafka/saveTopics`,
      method: 'POST',
      data: params,
      baseURL: '',
      noToken: ''
    })
  },
  getTopicByClusterIdAndName(params) {
    return request({
      url: `${baseAll}/kafka/getTopicByClusterIdAndName`,
      method: 'POST',
      data: params,
      baseURL: '',
      noToken: ''
    })
  },
  deleteTopicByClusterIdAndNames(params) {
    return request({
      url: `${baseAll}/kafka/deleteTopicByClusterIdAndNames`,
      method: 'POST',
      data: params,
      baseURL: '',
      noToken: ''
    })
  },
  deleteTopicByClusterNames(params) {
    return request({
      url: `${baseAll}/kafka/topics/` + params,
      method: 'DELETE',
      data: params,
      baseURL: '',
      noToken: ''
    })
  },
  checkOauth() {
    return request({
      url: `${baseAll}/rbac/checkOauth.json`,
      method: 'get',
      baseURL: '',
      noToken: ''
    })
  }
}
